var app = getApp();
var util = require('../../../../utils/util.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    isaufocus:true,
    id:-1,
    inputFBNum: "",
    isinput_col: false,  //收藏弹窗显隐
    ischoose_index: -1,   //选中规格样式 
    isInput: false,  //添加商品数量弹框及输入框焦点
    isInput2: false,  //特殊需求备注弹框的输入框焦点
    inputNum: "",   //添加商品弹窗的输入框中数量
    inputIndex: -1,    //主产品索引值 
    rightDatas: [
     
    ],
    shangpin:'',
    isfeibiao: false,  //添加非标品弹窗的显隐
    fbName: '',  //非标品名称
    fbNum: 0,   //非标品数量
    firstPerson: '',  //非标品的单位
    tanimg: "",   //弹窗商品图片
    tanname: "",  //弹窗商品名称
    tanunit: "",  //弹窗商品单位
    tangui: "",   //弹窗规格名称
    tannum: "",   //弹窗商品数量
    hide_good_box: true,  //动画小球的显隐
    tszhinput: "",     //备注输入框内容
    tszhcontent: "",   //备注内容
    page: 1,     //当前页码
    allpage:1,
    load: "搜索中...",
    selectdanwei: false,  //选择单位弹窗
    KeyboardKeys: [1, 2, 3, 4, 5, 6, 7, 8, 9, '·', 0], //键盘
    content: '',  //键盘初始空字符串
    loading:1,
    assign_super_index:-1,  //选择的供应商
    tan_is_auxiliary:0,  //当前商品是否开启辅助单位  0关闭，1开启
    aux_kucun_index:-1,   //库存商品辅助单位索引
    z_choose_supplier_id:-1,   //非标选择的供应商
    tan_shop_ku:0,  //当前商品是否属于库商品
    group_name:'',  //所加入的集团名称
    assign_superlist:[],
    aux_kucun_list:[],
    aux_pf_list:[], //gy_pf辅助单位列表
    aux_pf_index:-1, //gy_pf辅助单位索引
    btm_superlist:[],
    is_move_gif:false  //按钮动图
  },
  // 扫描商品条码
  saomiao_ck(){
    wx.scanCode({
      onlyFromCamera:true,   //值为 false  既可以使用相机也可以使用相册，  值为true 只能使用相机
      //  scanType:['barCode', 'qrCode','datamatrix','pdf417'], 
       //分别对应 一维码  二维码  DataMatrix码  PDF417条码  
      success: (res) => { //扫码成功后
        console.log(res)
        wx.showToast({
          title: '扫码成功',
          duration: 1000,
          mask: true
        });
        wx.navigateTo({
          url: '/shop_car_space/pages/shop_car/shop_car?supplier_id=' + this.data.id + '&supername=' +  this.data.supername+ '&is_ku=' + 1+'&price_type='+this.data.price_type+'&show_price_type='+this.data.show_price_type+'&is_sao_code='+1+'&sao_code='+res.result
          });
        },
        fail: (res) => {//扫码失败后
          wx.showToast({
             title: '扫码失败',
             icon: 'loading',
             duration: 1500
          })
        },
      complete:(res)=>{
        console.log(res);
      }
    })
  },
  // 去常用
  tofast:function(){
    wx.navigateTo({
      url: '/pages/changyong/changyong?supplier_id='+ this.data.id
    })
  },
  // 特殊需求备注弹窗输入内容
  tszhinput: function (e) {
    this.setData({
      tszhinput: e.detail.value
    })
  },
  // 打开特殊需求备注弹窗
  opentszh: function () {
    this.setData({
      isInput2: true,
      istszh: true,
      tszhinput: this.data.tszhcontent
    })
  },
  // 关闭特殊需求备注弹窗
  tszhcancel: function () {
    this.setData({
      isInput2: false,
      istszh: false
    })
  },
  // 确定并关闭需求备注弹窗
  tszhconfirm: function () {
    this.setData({
      isInput2: false,
      istszh: false,
      tszhcontent: this.data.tszhinput
    })
  },
  // 清空输入内容
  delcont:function(){
    var that = this;
    setTimeout(function (){
      that.setData({
        isaufocus:true,
        shangpin:'',
        rightDatas:[],
        guige: [],
        page: 1,
        load: "搜索中"
      })
    },100)
  },
  close_focus:function(){
    this.setData({
      isaufocus:false
    });
  },
  //点击切换
  mySelect: function (e) {
    util.hideBuyModal(this,"selectdanwei");
    this.setData({
      firstPerson: e.target.dataset.me,
      value: e.target.dataset.value
    })
  },
  //供应商未报价
  zero_price_but:function(){
    wx.showLoading({
      title:'供应商未报价',
      duration:500
    })
  },
  // 打开规格的收藏内容
  spesc_but: function (e) {
    var index = e.currentTarget.id;
    var is_up=e.currentTarget.dataset.is_up;  //是否下架及供应商数量
    var is_ku=e.currentTarget.dataset.is_ku;  //当前商品是否属于库存商品
    var is_zi_cai=this.data.is_zi_cai;  //是否自采
    var specs_count=e.currentTarget.dataset.specs_count;  //是否多规格
    var tan_is_auxiliary=e.currentTarget.dataset.is_auxiliary;  //是否开启辅助单位
    if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){ //模式5
      if(is_up*1+is_zi_cai*1==0 && is_ku==0){
        return;
      };
      if(is_ku==1){   //库存商品
        this.setData({
          is_move_gif:tan_is_auxiliary==1?true:false,
          tan_shop_ku:1,
          aux_kucun_index:-1,
          aux_kucun_list:[],
          tan_is_auxiliary:tan_is_auxiliary
        });
        if(tan_is_auxiliary==1){
          this.aux_kucun_fun(e.currentTarget.dataset.shopid);
        };
      }else if(is_ku==0){  //非库存商品
        this.setData({
          tan_shop_ku:0,
          tan_is_auxiliary:tan_is_auxiliary,
          assign_superlist:[],
          is_move_gif:true
        });
        if(specs_count==0){  //仅有主规格
          this.assign_super_fun(e.currentTarget.dataset.shopid,tan_is_auxiliary);
        }; 
      };
    }else{
      if(this.data.rightDatas[index].price_type<=2){  //供应-批发
        this.setData({
          aux_pf_index:-1,
          aux_pf_list:[],
          is_move_gif:tan_is_auxiliary==1?true:false,
          tan_is_auxiliary:tan_is_auxiliary,
        })
        if(tan_is_auxiliary==1 && specs_count==0){  //仅有主规格
          this.aux_gy_pf_fun(e.currentTarget.dataset.shopid);
        }; 
      }else{  //其他模式的企业
        this.setData({
          tan_is_auxiliary:tan_is_auxiliary,
          is_move_gif:false
        });
      }
    };
    this.setData({
      shopid: e.currentTarget.dataset.shopid,
      show_index:index,
      shop_is_same:this.data.rightDatas[index].is_same,
      ischoose_index: -1,
      tszhcontent: ''
    });
    this.tancontent(); 
  },
  // 收藏弹窗内容展示
  tancontent: function () {
    var that = this;
    app.AppHttp('api/Shopping/addCoolGoodsPage', {
      openid: app.globalData.openid,
      good_id: that.data.shopid,
      is_ku:1
    }, function (res) {
      console.log(JSON.stringify(res.data));
      that.setData({
        taninfo: res.data,    //弹窗数据
        isaufocus:false,
        isinput_col: true,
        shopnum: '',
        shoppr_num: '',
        assign_super_index:-1
      });
      if (res.data.specs_list.length == 1) {
        console.log(res.data.specs_list[0].price_type);
        that.setData({
          ischoose_index: 0,  //当规格只有一个时为选中状态
          tszhcontent: res.data.specs_list[0].remark?res.data.specs_list[0].remark:'', 
          shoppr_num: res.data.specs_list[0].pr_num,  //选中的产品是否已添加
          shop_price_type:res.data.specs_list[0].price_type,  //选中的产品价格类型
          shop_price:res.data.specs_list[0].true_price, //选中的产品的价格
          shop_b_price:res.data.specs_list[0].single_price,  //选中的产品B单价格
          shop_sale_price:res.data.specs_list[0].sale_price,  //选中的产品销售价
          shop_level_price:res.data.specs_list[0].level_true_price,  //级别A价
          shop_level_b_price:res.data.specs_list[0].level_single_price,  //级别B价
          tan_ku_price:that.data.shop_is_same==0?res.data.specs_list[0].stock_sale_price:res.data.specs_list[0],
          tan_ku_num:res.data.specs_list[0].stock_num_show,
          is_tan_ku_price:res.data.specs_list[0].is_show_stock_price,
          is_tan_ku_num:res.data.specs_list[0].is_show_stock_num
        });
      }else{
        that.setData({
          assign_superlist:[]
        });
      }
    });
  },
  // 选定条件后打开底部弹窗
  open_tan_info:function(e){
    if(this.data.ischoose_index>=0){
      util.showBuyModal(this);
      var taninfo = this.data.taninfo;
      if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){   //模式5
        if(this.data.tan_shop_ku==1){    //库存商品
          if(this.data.tan_is_auxiliary==0){   //未开启辅助单位
            this.setData({
              assign_super_index:-1,
              aux_kucun_index:-1,
              aux_kucun_list:[],
            });
          }else if(this.data.tan_is_auxiliary==1){  //开启了辅助单位
            if(this.data.aux_kucun_list.length==1){  //仅有一条辅助单位
              this.setData({
                assign_super_index:-1,
                aux_kucun_index:0,
                shoppr_num: this.data.aux_kucun_list[0].pr_num,
              });
            }else{
              this.setData({
                assign_super_index:-1,
                aux_kucun_index:e.currentTarget.dataset.index,
                shoppr_num: this.data.aux_kucun_list[e.currentTarget.dataset.index].pr_num
              });
            };     
          };
        }else if(this.data.tan_shop_ku==0){  //非库存商品
          if(this.data.assign_superlist.length==0){  //自采
            this.setData({
              aux_kucun_index:-1,
              aux_kucun_list:[],
              assign_super_index:-10010
            });
            this.zicai_pr_num(taninfo.specs_list[this.data.ischoose_index].id);
          }else if(this.data.assign_superlist.length==1 && this.data.is_zi_cai==0){  //仅一个供应商+未开自采
            this.setData({
              aux_kucun_index:-1,
              aux_kucun_list:[],
              assign_super_index:0,
              shoppr_num:this.data.assign_superlist[0].pr_num
            });
          }else{
            if(e.currentTarget.dataset.index!=-10010){
              this.setData({
                shoppr_num:this.data.assign_superlist[e.currentTarget.dataset.index].pr_num
              });
            }else if(e.currentTarget.dataset.index==-10010){
              this.zicai_pr_num(taninfo.specs_list[this.data.ischoose_index].id);
            };
            this.setData({
              aux_kucun_index:-1,
              aux_kucun_list:[],
              assign_super_index:e.currentTarget.dataset.index,
            });  
          }
        }  
      }else{  //其他
        if(taninfo.specs_list[this.data.ischoose_index].price_type<=2){  //供应-批发
          if(this.data.tan_is_auxiliary==0){
            this.setData({
              aux_pf_index:-1,
              aux_pf_list:[],
            });
          }else if(this.data.tan_is_auxiliary==1){
            if(this.data.aux_pf_list.length==1){   //仅一条辅助单位
              this.setData({
                aux_pf_index:0,
                shoppr_num:this.data.aux_pf_list[0].pr_num 
              })
            }else{
              this.setData({
                aux_pf_index:e.currentTarget.dataset.index,
                shoppr_num:this.data.aux_pf_list[e.currentTarget.dataset.index].pr_num  
              })
            }
          }
        }   
      }
      let tan_true_price='';
      let tan_single_price='';
      if(this.data.price_type==2){
        tan_true_price=taninfo.specs_list[this.data.ischoose_index].level_true_price;
        tan_single_price=taninfo.specs_list[this.data.ischoose_index].level_single_price;
      }else{
        tan_true_price=taninfo.specs_list[this.data.ischoose_index].true_price;
        tan_single_price=taninfo.specs_list[this.data.ischoose_index].single_price;
      };
      this.setData({
        content:'',
        isInput: true,
        tanimg: taninfo.goodInfo.cover,
        tanname: taninfo.goodInfo.trade_name,
        tanalias:taninfo.goodInfo.trade_alias,
        tanspecs:taninfo.specs_list[this.data.ischoose_index].specs,
        tan_fixed_show:taninfo.specs_list[this.data.ischoose_index].is_show_price,  //是否显示固定价
        tanunit_index:taninfo.specs_list[this.data.ischoose_index].help_unit>0?taninfo.specs_list[this.data.ischoose_index].help_unit:taninfo.specs_list[this.data.ischoose_index].unit,
        tanunit:taninfo.specs_list[this.data.ischoose_index].help_unit>0?taninfo.specs_list[this.data.ischoose_index].help_unit_name:taninfo.specs_list[this.data.ischoose_index].unit_name,
        tanunit_init: taninfo.specs_list[this.data.ischoose_index].unit_name,
        tan_true_price:tan_true_price,
        tan_single_price:tan_single_price, 
        tan_sale_price:taninfo.specs_list[this.data.ischoose_index].sale_price,
        tan_price_type: taninfo.specs_list[this.data.ischoose_index].price_type
      });
    }else{
      wx.showLoading({
        title:'请选择规格',
        duration:500
      })
    };
  },
  col_setValue:function(){
    this.setData({
      shopnum: this.data.content
    });
    console.log(this.data.shopnum);
  },
  // 取消关闭添加商品弹窗
  cancel_col: function () {
    this.setData({
      isinput_col: false
    });
  },
  // 选择商品规格
  chose_specs: function (e) {
    var index = e.currentTarget.dataset.index;
    var item=this.data.taninfo.specs_list[index];
    if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1 && this.data.tan_shop_ku==0 && item.tan_is_auxiliary==1 && index>0){
      wx.showModal({
        title: '提示',
        content:'当非库存商品开启辅助单位功能后，商品其他规格则被锁定',
        showCancel: false,
        confirmText:"我知道了",
        success: function (res) {}
      });   
      return;
    }else if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1 && this.data.tan_shop_ku==0 && (item.is_auxiliary==1 && item.is_aux_up*1+this.data.is_zi_cai*1==0 || item.is_auxiliary==0 && item.is_up*1+this.data.is_zi_cai*1==0)){
      wx.showModal({
        title: '提示',
        content:'当前规格无可选供应商',
        showCancel: false,
        confirmText:"我知道了",
        success: function (res) {}
      });
      return;
    };
    var is_zi_cai=this.data.is_zi_cai;
    this.setData({
      ischoose_index: index,
      tszhcontent:item.remark?item.remark:'',
      shopid:item.id,  //选中的产品id
      shoppr_num:item.pr_num,  //选中的产品是否已添加
      shop_price_type:item.price_type,  //选中的产品价格类型
      shop_price:item.true_price, //选中的产品的价格
      shop_b_price:item.single_price,  //选中的产品B单价格
      shop_sale_price:item.sale_price,  //选中的产品销售价
      shop_level_price:item.level_true_price,  //级别A价
      shop_level_b_price:item.level_single_price,  //级别B价
      tan_is_auxiliary:item.is_auxiliary,  //当前规格辅助单位是否开启
      shop_is_same:item.is_same,  //是否开启采销同价
      tan_ku_price:item.is_same==0?item.stock_sale_price:item.stock_price_show,
      tan_ku_num:item.stock_num_show,
      is_tan_ku_price:item.is_show_stock_price,
      is_tan_ku_num:item.is_show_stock_num,
      assign_super_index:-1,
      assign_superlist:[],
      aux_pf_index:-1,
      aux_pf_list:[],
    });
    if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1 && this.data.tan_shop_ku==0){   //模式5+非库存商品    
      this.setData({
        is_move_gif:true
      });
      this.assign_super_fun(item.id,this.data.tan_is_auxiliary);    
    }else{
      this.setData({
        is_move_gif:this.data.tan_is_auxiliary==1?true:false
      });
      if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1 && this.data.tan_shop_ku==1 && this.data.tan_is_auxiliary==1){  //库存+辅助
        this.aux_kucun_fun(item.id);   
      }else{  
        if(item.price_type<=2){  //供应-批发
          if(this.data.tan_is_auxiliary==1){ //是辅助单位
            this.setData({
              is_move_gif:true
            });
            this.aux_gy_pf_fun(item.id)
          }else if(this.data.tan_is_auxiliary==0){  //非辅助单位
            this.setData({
              is_move_gif:false
            });
            this.open_tan_info();
          } 
        }else{
          this.open_tan_info();
        }
      };
    }
  },
  // 添加并收藏的接口
  addorder(e) {
    var that = this;
    var shopnum = that.data.shopnum;
    if (that.data.ischoose_index == -1) {
      wx.showLoading({
        title: '请选择规格',
        duration: 500
      });
      return;
    }else if(that.data.shopnum==0){
      if(that.data.shopnum != ''){ //输入0
        shopnum=0;
      }else if(that.data.shopnum == ''){ //不输入
        shopnum = that.data.shoppr_num;
      };
      if(shopnum==0){
        wx.showLoading({
          title:'输入不能为0',
          duration:500
        });
        return;
      };
    };
    if (shopnum > 9999.99) {
      wx.showToast({
        title: '数量过大'
      })
      return;
    };
    var aux_obj={'is_aux':0,'pr_unit':that.data.tanunit_index,'sub_unit_num':1};
    if(that.data.shop_price_type==1 || that.data.shop_price_type==2){
      if(that.data.price_type==2){      //客户级别价
        if(this.data.tan_is_auxiliary==1){  //是辅助单位
          if(that.data.aux_pf_list.length==0){   //当接口还未获取到辅助单位列表时return
            return;
          };
          var aux_item=that.data.aux_pf_list[that.data.aux_pf_index];
          var nor_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
          aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
          app.myMethod.updateGood(that.data.id,this.data.b_supplier_id,that.data.shopid,shopnum, that.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else{     //非辅助单位
          app.myMethod.updateGood(that.data.id,this.data.b_supplier_id,that.data.shopid, shopnum, that.data.tszhcontent,that.data.shop_level_price,that.data.shop_level_b_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }
      }else if(that.data.price_type==1){ //客户历史价
        if(this.data.tan_is_auxiliary==1){ //是辅助单位
          if(that.data.aux_pf_list.length==0){   //当接口还未获取到辅助单位列表时return
            return;
          };
          var aux_item=that.data.aux_pf_list[that.data.aux_pf_index];
          var nor_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
          aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
          app.myMethod.updateGood(that.data.id,this.data.b_supplier_id,that.data.shopid,shopnum, that.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num,'',nor_price_obj.true_price);
        }else{ //非辅助单位
          app.myMethod.updateGood(this.data.id,this.data.b_supplier_id,that.data.shopid, shopnum, that.data.tszhcontent,0,0,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num,'',that.data.shop_price);
        }
      }else if(that.data.price_type==4){  //客户固定价
        if(this.data.tan_is_auxiliary==1){  //是辅助单位
          if(that.data.aux_pf_list.length==0){   //当接口还未获取到辅助单位列表时return
            return;
          };
          var aux_item=that.data.aux_pf_list[that.data.aux_pf_index];
          var nor_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
          aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
          app.myMethod.updateGood(that.data.id,this.data.b_supplier_id,that.data.shopid,shopnum, that.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else{     //非辅助单位
          app.myMethod.updateGood(that.data.id,this.data.b_supplier_id,that.data.shopid, shopnum, that.data.tszhcontent,that.data.shop_price,that.data.shop_b_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        };
      }else{   //客户询价
        if(this.data.tan_is_auxiliary==1){  //是辅助单位
          if(that.data.aux_pf_list.length==0){   //当接口还未获取到辅助单位列表时return
            return;
          };
          var aux_item=that.data.aux_pf_list[that.data.aux_pf_index];
          var nor_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
          aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
          app.myMethod.updateGood(that.data.id,this.data.b_supplier_id,that.data.shopid,shopnum, that.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else{     //非辅助单位
          app.myMethod.updateGood(this.data.id,this.data.b_supplier_id,that.data.shopid, shopnum, that.data.tszhcontent,0,0,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        };
      }
    }else if(that.data.shop_price_type==3){
      if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){ //模式5
        if(this.data.tan_shop_ku==1){  //库存
          if(this.data.is_ctrl_stock==1 && shopnum>0 && shopnum*1>this.data.tan_ku_num*1){
            wx.showLoading({
              title:'库存不足',
              duration:500
            });
            return;
          };
          var kucun_price_obj={'true_price':that.data.tan_ku_price,'single_price':0};
          if(this.data.tan_is_auxiliary==1){  //是辅助单位
            if(that.data.aux_kucun_list.length==0){   //当接口还未获取到库存辅助单位列表时return
              return;
            };
            var aux_item=that.data.aux_kucun_list[that.data.aux_kucun_index];
            aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
            if(this.data.shop_is_same==0){  //是否开启采销同价
              kucun_price_obj={'true_price':aux_item.sale_price,'single_price':aux_item.sale_price};
            }else if(this.data.shop_is_same==1){
              kucun_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
            };
          };
          app.myMethod.updateGood(this.data.id,this.data.group_id,that.data.shopid,shopnum, this.data.tszhcontent,kucun_price_obj.true_price,kucun_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else if(this.data.tan_shop_ku==0){  //非库存
          if(this.data.is_zi_cai==0 || that.data.assign_super_index>-1){  //非自采
            if(this.data.assign_superlist.length==0){   //当接口还未获取到供应商时return
              return;
            };
            var assign_item=that.data.assign_superlist[that.data.assign_super_index];
            var nor_price_obj={'true_price':that.data.shop_price,'single_price':0};
            if(this.data.tan_is_auxiliary==1){  //是辅助单位
              aux_obj={'is_aux':1,'pr_unit':assign_item.sub_unit,'sub_unit_num':assign_item.sub_unit_num};
              nor_price_obj={'true_price':assign_item.sub_price,'single_price':assign_item.sub_price};
            };
            app.myMethod.updateGood(this.data.id,assign_item.supplier_id,that.data.shopid, shopnum, that.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num,assign_item.submit_price);
          }else if(this.data.is_zi_cai==1 && that.data.assign_super_index==-10010){  //自采
            app.myMethod.updateGood(-10010,-10010,that.data.shopid,shopnum,that.data.tszhcontent,that.data.shop_price,0,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
          };  
        };
      }else if(this.data.good_dir_set==2 && this.data.purchase_type==2){  //模式6,7
        app.myMethod.updateGood(this.data.id,this.data.group_id,that.data.shopid,shopnum, this.data.tszhcontent,that.data.shop_price,0,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
      }else{   //模式1,4及其他
        app.myMethod.updateGood(this.data.id,this.data.b_supplier_id, that.data.shopid, shopnum, that.data.tszhcontent,that.data.shop_price,0,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
      };   
    }else if(that.data.shop_price_type==4){
      if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){  //模式5
        if(this.data.tan_shop_ku==1){
          if(this.data.is_ctrl_stock==1 && shopnum>0 && shopnum*1>this.data.tan_ku_num*1){
            wx.showLoading({
              title:'库存不足',
              duration:500
            });
            return;
          };
          var kucun_price_obj={'true_price':that.data.tan_ku_price,'single_price':that.data.tan_ku_price};
          if(this.data.tan_is_auxiliary==1){  //是辅助单位
            if(that.data.aux_kucun_list.length==0){   //当接口还未获取到库存辅助单位列表时return
              return;
            };
            var aux_item=that.data.aux_kucun_list[that.data.aux_kucun_index];
            aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
            if(this.data.shop_is_same==0){  //是否开启采销同价
              kucun_price_obj={'true_price':aux_item.sale_price,'single_price':aux_item.sale_price};
            }else if(this.data.shop_is_same==1){
              kucun_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
            };
          };
          app.myMethod.updateGood(this.data.id,this.data.group_id,that.data.shopid,shopnum, this.data.tszhcontent,kucun_price_obj.true_price,kucun_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else if(this.data.tan_shop_ku==0){
          if(this.data.is_zi_cai==0 || that.data.assign_super_index>-1){  //非自采
            if(this.data.assign_superlist.length==0){   //当接口还未获取到供应商时return
              return;
            };
            var assign_item=that.data.assign_superlist[that.data.assign_super_index];
            var nor_price_obj={'true_price':assign_item.unit_price,'single_price':assign_item.unit_price};
            if(this.data.tan_is_auxiliary==1){  //是辅助单位
              aux_obj={'is_aux':1,'pr_unit':assign_item.sub_unit,'sub_unit_num':assign_item.sub_unit_num};
              nor_price_obj={'true_price':assign_item.sub_price,'single_price':assign_item.sub_price};
            };
            app.myMethod.updateGood(this.data.id,assign_item.supplier_id,that.data.shopid,shopnum,that.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num,assign_item.submit_price);
          }else if(this.data.is_zi_cai==1 && that.data.assign_super_index==-10010){  //自采
            app.myMethod.updateGood(-10010,-10010,that.data.shopid,shopnum,that.data.tszhcontent,that.data.shop_price,that.data.shop_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
          };     
        }
      }else if(this.data.good_dir_set==2 && this.data.purchase_type==2){  //模式6,7
        app.myMethod.updateGood(this.data.id,this.data.group_id,that.data.shopid,shopnum, this.data.tszhcontent,that.data.shop_price,that.data.shop_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
      }else{    //模式1,4及其他
        app.myMethod.updateGood(this.data.id,this.data.b_supplier_id,that.data.shopid, shopnum, that.data.tszhcontent,that.data.shop_price,that.data.shop_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
      };
    }else if(that.data.shop_price_type==5){
      if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){  //模式5
        if(this.data.tan_shop_ku==1){
          if(this.data.is_ctrl_stock==1 && shopnum>0 && shopnum*1>this.data.tan_ku_num*1){
            wx.showLoading({
              title:'库存不足',
              duration:500
            });
            return;
          };
          var kucun_price_obj={'true_price':that.data.tan_ku_price,'single_price':that.data.tan_ku_price};
          if(this.data.tan_is_auxiliary==1){  //是辅助单位
            if(that.data.aux_kucun_list.length==0){   //当接口还未获取到库存辅助单位列表时return
              return;
            };
            var aux_item=that.data.aux_kucun_list[that.data.aux_kucun_index];
            aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
            if(this.data.shop_is_same==0){  //是否开启采销同价
              kucun_price_obj={'true_price':aux_item.sale_price,'single_price':aux_item.sale_price};
            }else if(this.data.shop_is_same==1){
              kucun_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
            };
          };
          app.myMethod.updateGood(this.data.id,this.data.group_id,that.data.shopid,shopnum, this.data.tszhcontent,kucun_price_obj.true_price,kucun_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else if(this.data.tan_shop_ku==0){
          if(this.data.is_zi_cai==0 || that.data.assign_super_index>-1){  //非自采
            if(this.data.assign_superlist.length==0){   //当接口还未获取到供应商时return
              return;
            };
            var assign_item=that.data.assign_superlist[that.data.assign_super_index];
            var nor_price_obj={'true_price':assign_item.unit_price,'single_price':assign_item.unit_price};
            if(this.data.tan_is_auxiliary==1){  //是辅助单位
              aux_obj={'is_aux':1,'pr_unit':assign_item.sub_unit,'sub_unit_num':assign_item.sub_unit_num};
              nor_price_obj={'true_price':assign_item.sub_price,'single_price':assign_item.sub_price};
            };
            app.myMethod.updateGood(this.data.id,assign_item.supplier_id,that.data.shopid, shopnum, that.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num,assign_item.submit_price);
          }else if(this.data.is_zi_cai==1 && that.data.assign_super_index==-10010){  //自采
            app.myMethod.updateGood(-10010,-10010,that.data.shopid, shopnum,that.data.tszhcontent,that.data.shop_sale_price,that.data.shop_sale_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
          };
        };    
      }else if(this.data.good_dir_set==2 && this.data.purchase_type==2){  //模式6,7
        app.myMethod.updateGood(this.data.id,this.data.group_id,that.data.shopid,shopnum, this.data.tszhcontent,that.data.shop_sale_price,that.data.shop_sale_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
      }else{    //模式1,4及其他
        app.myMethod.updateGood(this.data.id,this.data.b_supplier_id,that.data.shopid, shopnum, that.data.tszhcontent,that.data.shop_sale_price,that.data.shop_sale_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
      };
    };
    if(this.data.isInput==true){
      util.hideBuyModal(this,"isInput");
    };
    that.setData({
      shangpin:'',
      isaufocus:true,
      isinput_col: false
    });
    if(this.data.taninfo.specs_list.length==1){  //一条规格时
      that.setData({
        ["rightDatas[" + that.data.show_index + "].pr_num"]:shopnum
      });
    };
    if (shopnum > 0) {    //添加商品数量大于0时，执行抛物线方法
      util.touchOnGoods(that,e.touches["0"],that.data.id,'nopand',1);
      that.setData({
        ["rightDatas[" + that.data.show_index + "].is_show"]: 1
      });
    } else {
      util.car_total(that,that.data.id,1);
      this.data.taninfo.specs_list[that.data.ischoose_index].pr_num = 0;
      for (var i in that.data.taninfo.specs_list) {
        console.log(i);
        if (that.data.taninfo.specs_list[i].pr_num > 0) {
          that.setData({
            ["rightDatas[" + that.data.show_index + "].is_show"]: 1
          });
          return;
        }
      }
      that.setData({
        ["rightDatas[" + that.data.show_index + "].is_show"]: 0
      });
    }
  },
  // 打开添加非标品弹窗
  addFBTap(){
    this.setData({
      isaufocus:false,
      isfeibiao: true,
      fbNum: 0,
      fbName: "",
      firstPerson:"",
      z_choose_supplier_id:-1
    });
  },
  // 非标品单位列表
  feibiao: function () {
    var that = this;
    app.AppHttp('api/Goods/addNoProduct', { }, function (res) {
      // console.log(JSON.stringify(res.data));
      that.setData({
        unit_list: res.data.unit_list
      })
    }) 
  },
  // 关闭添加非标品弹窗
  feibiaocancel(){
    this.setData({
      isfeibiao: false,
      tszhcontent: ''
    });
  },
  // 选择供应商
  chose_super:function(){
    var that = this;
    util.showBuyModal(this);  
    that.setData({
      issuper:true
    });
    app.AppHttp("api/Client/belongBusinessSupplier", {
      client_id:app.globalData.loginInfo.id
    }, function(res) { 
      console.log(JSON.stringify(res.data));
      that.setData({
        btm_superlist:res.data
      });
    });
  },
  // 确定供应商
  super_conf:function(e){
    var supplier_id=e.currentTarget.dataset.supplier_id;
    var company_name=e.currentTarget.dataset.company_name;
    this.setData({
      z_choose_supplier_id:supplier_id,
      z_choose_supplier_name:company_name
    });
    util.hideBuyModal(this,"issuper");
  },
  // 关闭供应商
  close_super:function(){
    util.hideBuyModal(this,"issuper");
  },
  /**
   * 非标品确认添加
   */
  feibiaoconfirm: function (event) {
    var that = this;
    var fbNum = that.data.fbNum;
    var fbName = that.data.fbName;
    var fbDanWei = that.data.value;
    var supplier_id = that.data.id;
    if (fbName == '') {
      wx.showLoading({
        title:'请输入名称',
        duration:500
      });
    } else if (fbDanWei == '') {
      wx.showLoading({
        title:'请选择单位',
        duration:500
      });
    }else {
      console.log("非标品名字--" + fbName + "--非标品数量--" + fbNum + "--非标品单位--" + fbDanWei);
      var z_choose_supplier_id=0; //0代表不选供应商
      if(that.data.good_dir_set==2 && that.data.client_is_store==0 && that.data.purchase_type==1){ //模式5
        if(that.data.z_choose_supplier_id==-1){
          wx.showLoading({
            title:'请选择供应商',
            duration:500
          });
          return;
        }else{
          z_choose_supplier_id=that.data.z_choose_supplier_id;
          if(z_choose_supplier_id==-10010){  //选择了自采
            supplier_id=-10010;
          };
        };
      };
      wx.request({
        url: app.globalData.url + 'api/Goods/addNoProductDo',
        method: 'POST',
        data: {
          openid: app.globalData.openid,
          supplier_id: supplier_id,
          b_supplier_id:that.data.good_dir_set==2 && that.data.purchase_type==2?that.data.group_id:z_choose_supplier_id,    //模式6,7选企业的id
          pr_name: "**"+fbName,
          pr_unit: fbDanWei,
          num: fbNum,
          remark: that.data.tszhcontent,
          one_class:0
        },
        success: function (res) {
          console.log(JSON.stringify(res.data));
          app.globalData.changyong_show=1;
          if (fbNum > 0) {
            that.setData({
              shangpin:'',
              isaufocus:true,
              isfeibiao: false
            });
            util.touchOnGoods(that,event.touches["0"],that.data.id,'nopand',1);
          }
        },
      })
      that.setData({
        tszhcontent: ''
      })
    }
  },
  fbminTap: function (event) {
    var fbNum = event.currentTarget.dataset.id;
    if(fbNum<1){
      fbNum=0;
    }else{
      fbNum--; 
      if((fbNum*1)%1!=0){
        fbNum=parseFloat((fbNum*1).toFixed(2));
      };  
    };
    this.setData({
      fbNum: fbNum,
      holderFBNum: fbNum
    })
  },
  fbnumInput: function (event) {
    util.showBuyModal(this);
    var index = event.currentTarget.dataset.id;;
    this.setData({
      content:'',
      isInput:true,
      tan_single_price:'',
      tan_sale_price:'',
      inputIndex: index,
      holderFBNum: this.data.fbNum,
      inputFBNum: '',
      assign_super_index:-1,
      is_move_gif:false,
      assign_superlist:[],
      tanimg:'/upload/smallprogram/noshopimg.png',
      tanname: this.data.fbName?this.data.fbName:'未填写名称',
      tanunit: this.data.firstPerson
    });
  },
  fbaddTap: function (event) {
    var fbNum = event.currentTarget.dataset.id;
    fbNum = parseFloat(fbNum);
    fbNum++;
    this.setData({
      fbNum: fbNum,
      holderFBNum: fbNum
    })
  },
  // 非标品名称输入
  setFBName: function (event) {
    var fbName = event.detail.value;
    this.setData({
      fbName: fbName
    })
  },
  // 非标品单位弹窗
  setFBDanWei: function (event) {
    var fbDanWei = this.data.firstPerson;
    var selectdanwei = this.data.selectdanwei;
    if (selectdanwei == true) {   
      util.hideBuyModal(this,"selectdanwei");
    } else {
      util.showBuyModal(this);
      this.setData({
        selectdanwei: true
      })
    }
  },
  confirmfb: function () {
    if (this.data.inputFBNum > 9999.99) {
      wx.showToast({
        title: '数量过大',
      })
      return;
    }
    if (this.data.inputFBNum == ''){
        util.hideBuyModal(this,"isInput");
        this.setData({
          holderFBNum:""
        });
    }else{
      var fbNum = this.data.inputFBNum * 1;
      util.hideBuyModal(this,"isInput");
      this.setData({
        fbNum:fbNum,
        holderFBNum:""
      });
    } 
  },
  // 去购物车页面
  gouWuCheTap: function () {
    wx.navigateTo({
      url: '/shop_car_space/pages/shop_car/shop_car?supplier_id=' + this.data.id + '&supername=' + this.data.supername+ '&is_ku=' + 1+'&price_type='+this.data.price_type+'&show_price_type='+this.data.show_price_type
    });
  },
  inputck:function(e){
    var shangpin=e.detail.value;
    this.setData({
      shangpin:shangpin
    });
    app.globalData.task.abort();  //中断上一次搜索
    this.viewck();
  },
  viewck: function (){
    this.setData({
      rightDatas:[],
      guige: [],
      page: 1,
      load: "搜索中"
    });
    this.upshoplist();
  },
  upshoplist: function () {
    if(this.data.page==1){
      wx.showLoading({
        title: this.data.load
      });
    }; 
    var that = this;
    var v = that.data.shangpin;
    app.AppHttp('api/Goods/SearchGood', {
      keyword: v,
      supplier_id: that.data.id,
      openid: app.globalData.openid,
      page: that.data.page,
      limit: 20,
      submit_type:1,
      is_ku:1
    }, function (res) {
      console.log(JSON.stringify(res));
      if (that.data.page == 1) {
        that.setData({
          loading:0,
          rightDatas: res.data[0],
          allpage: res.data[1]
        });
      } else {
        that.setData({
          loading:0,
          rightDatas: that.data.rightDatas.concat(res.data[0]),
          allpage: res.data[1]
        });
      }
      wx.hideLoading()
    });
  },
  searchClick: function () {
    app.globalData.task.abort();  //中断上一次搜索
    this.viewck();
  },
  itemAddClick: function (e) {
    this.numInput(e)
  },
  numInput: function (e) {
    var index = e.currentTarget.id;
    var info = this.data.rightDatas[index];
    var is_up=e.currentTarget.dataset.is_up;   //是否下架
    var is_ku=e.currentTarget.dataset.is_ku;   //是否属于库存商品
    var is_zi_cai=this.data.is_zi_cai;   //客户是否自采
    var tan_is_auxiliary=e.currentTarget.dataset.is_auxiliary;  //是否开启辅助单位
    if(this.data.good_dir_set==1){  
      tan_is_auxiliary=0;  //供应商目录 的 相关辅助单位（等企业相关辅助单位完善后可做），目前假定没有辅助单位
    };
    if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){  //模式5
      if(is_up*1+is_zi_cai*1==0 && is_ku==0){
        return;
      };
      if(is_ku==0){
        this.setData({
          tan_shop_ku:0,  //当前商品不属于库商品
          assign_superlist:[]
        });
        if(is_zi_cai==0){  //非自采
          this.setData({
            is_move_gif:true,
            tan_is_auxiliary:tan_is_auxiliary,
            assign_super_index:0,
            aux_kucun_index:-1,
            aux_kucun_list:[],
          });
          this.assign_super_fun(info.id,tan_is_auxiliary);
        }else if(is_zi_cai==1){  //自采
          this.setData({
            assign_super_index:-10010,
            aux_kucun_index:-1,
            aux_kucun_list:[],
            is_move_gif:false,
            tan_is_auxiliary:tan_is_auxiliary
          });
        };
      }else if(is_ku==1){
        if(this.data.is_ctrl_stock==1 && info.stock_num_show<=0){
          wx.showLoading({
            title:'库存不足',
            duration:500
          });
          return;
        };
        this.setData({
          tan_is_auxiliary:tan_is_auxiliary,
          assign_super_index:-1,
          aux_kucun_index:tan_is_auxiliary==1?0:-1,
          is_move_gif:tan_is_auxiliary==1?true:false,
          tan_shop_ku:1  //当前商品属于库商品
        });
        if(tan_is_auxiliary==1){
          this.aux_kucun_fun(info.id);
        };
      };  
    }else{
      if(info.price_type<=2){ //供应-批发
        this.setData({
          aux_pf_list:[],
          tan_is_auxiliary:tan_is_auxiliary
        })
        if(tan_is_auxiliary==0){
          this.setData({
            aux_pf_index:-1,
            is_move_gif:false
          })
        }else if(tan_is_auxiliary==1){ //辅助单位
          this.setData({
            aux_pf_index:0,
            is_move_gif:true
          })
          this.aux_gy_pf_fun(info.id);
        };
      }else{
        this.setData({
          tan_is_auxiliary:tan_is_auxiliary,
          assign_super_index:-1,
          is_move_gif:false
        });
      }
    };  
    util.showBuyModal(this);
    let tan_true_price='';
    let tan_single_price='';
    if(this.data.price_type==2){
      tan_true_price=info.level_true_price;
      tan_single_price=info.level_single_price;
    }else{
      tan_true_price=info.true_price;
      tan_single_price=info.single_price;
    };
    this.setData({
      content:'',
      tszhcontent:'',
      ischoose_index:0,
      isaufocus:false,
      isInput: true,
      inputIndex: index,
      inputNum: '',
      tanimg: info.cover,
      tanname: info.trade_name,
      tanalias:info.trade_alias,
      tanspecs:info.specs,
      tan_fixed_show:info.is_show_price,  //是否显示固定价
      tanunit_index: info.help_unit>0?info.help_unit:info.unit,
      tanunit: info.help_unit>0?info.help_unit_name:info.unit_name,
      tanunit_init:info.unit_name,
      tannum: info.pr_num,
      tan_price_type:info.price_type,
      tan_true_price:tan_true_price,
      tan_single_price:tan_single_price,
      tan_sale_price:info.sale_price,
      shop_is_same:info.is_same,  //是否开启了采销同价
      tan_ku_price:info.is_same==0?info.stock_sale_price:info.stock_price_show,
      tan_ku_num:info.stock_num_show,
      is_tan_ku_price:info.is_show_stock_price,
      is_tan_ku_num:info.is_show_stock_num
    }); 
  },
  // 选择菜品时的供应商和价格
  assign_super_fun:function(good_id,is_aux){
    var that = this;
    app.AppHttp('api/Shopping/getGoodSupplierInfo', {
      order_id:0,
      client_id: app.globalData.loginInfo.id,
      good_id:good_id,
      is_aux:is_aux
    }, function (res) {
      console.log(JSON.stringify(res.data));   
      that.setData({
        is_move_gif:false,
        assign_superlist:res.data
      }); 
      if(that.data.is_zi_cai==1){  //开通自采
        that.zicai_pr_num(good_id);
      };
      if(that.data.isinput_col && (res.data.length==0 && that.data.is_zi_cai==1 || res.data.length==1 && that.data.is_zi_cai==0)){   //当收藏弹窗显示时，才有可能调用
        that.open_tan_info();
      }; 
    }); 
  },
  // 库存辅助单位接口
  aux_kucun_fun(good_id){
    var that = this; 
    app.AppHttp('api/Shopping/getStockAuxUnit', {
      order_id:0,
      good_id:good_id,
      client_id:app.globalData.loginInfo.id
    }, function (res) {
      console.log(JSON.stringify(res.data));  
      that.setData({
        is_move_gif:false,
        aux_kucun_list:res.data
      });
      if(that.data.isinput_col && res.data.length==1){   //当收藏弹窗显示时，才有可能调用
        that.open_tan_info();
      };
    });  
  },
  // 供应-批发端辅助单位接口
  aux_gy_pf_fun(good_id){
    var that = this; 
    app.AppHttp('api/Shopping/getSupplierGoodsAux', {
      order_id:0,
      client_id:app.globalData.loginInfo.id,
      good_id:good_id,
      supplier_id:that.data.id
    }, function (res) {
      console.log(JSON.stringify(res.data)); 
      let aux_pf_list=[];
      if(res.data.goodsAuxiliaryList.length>0){
        aux_pf_list = res.data.goodsAuxiliaryList.filter((c,i) => {
          if(c.is_order_unit==1){
            if(that.data.price_type==2){
              res.data.goodsAuxiliaryList[i].sub_price = res.data.goodsAuxiliaryList[i].level_sub_price;
              return true;
            }else{
              res.data.goodsAuxiliaryList[i].sub_price = res.data.goodsAuxiliaryList[i].his_sub_price;
              return true;
            };
          };
        });
      };
      that.setData({
        is_move_gif:false,
        aux_pf_list:aux_pf_list
      });
      if((that.data.price_type==1 || that.data.price_type==4) && aux_pf_list.length==0){
        that.setData({
          tan_is_auxiliary:0 //**有辅助单位，但还没有历史价，按无辅助单位处理
        })
        if(that.data.isinput_col){
          that.open_tan_info();
        }
      };
      if((that.data.isinput_col || that.data.is_open_type=='normal') && aux_pf_list.length==1){   //当收藏弹窗显示时，才有可能调用
        that.open_tan_info();
      };
    });  
  },
  // 自采在购物车中的的数量
  zicai_pr_num(good_id){
    var that = this; 
    app.AppHttp('api/Shopping/getShopSelfMining', {
      openid:app.globalData.openid,
      good_id:good_id
    }, function (res) {
      console.log(JSON.stringify(res.data));  
      if(res.data.data){
        that.setData({
          zi_tannum:res.data.data.pr_num,
          tannum:res.data.data.pr_num,
          shoppr_num:res.data.data.pr_num
        });
      }else{
        that.setData({
          zi_tannum:0,
          tannum:0,
          shoppr_num:0
        });
      }; 
    });
  },
  setValue: function (event) {
    this.setData({
      inputNum: this.data.content
    });
  },
  fbsetValue: function (event) {
    this.setData({
      inputFBNum: this.data.content
    });
  },
  confirm(event) {
    if (this.data.inputNum == 0){
      if(this.data.inputNum != '' || this.data.tannum==0){
        wx.showLoading({
          title:'输入不能为0',
          duration:500
        });
        return;
      }else{
        this.setData({
          inputNum:this.data.tannum
        });
      }  
    };
    var info = this.data.rightDatas[this.data.inputIndex];
    if (this.data.inputNum>9999.99){
      wx.showToast({
        title: '数量过大',
      })
      return;
    };
    info.pr_num = this.data.inputNum == '' ? 0 : this.data.inputNum * 1;
    var aux_obj={'is_aux':0,'pr_unit':this.data.tanunit_index,'sub_unit_num':1};
    if(info.price_type==1 || info.price_type==2){
      if(this.data.price_type==2){      //客户级别价
        if(this.data.tan_is_auxiliary==1){  //是辅助单位
          if(this.data.aux_pf_list.length==0){   //当接口还未获取到辅助单位列表时return
            return;
          };
          var aux_item=this.data.aux_pf_list[this.data.aux_pf_index];
          var nor_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
          aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
          app.myMethod.updateGood(this.data.id,this.data.b_supplier_id,info.id,info.pr_num, this.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else{     //非辅助单位
          app.myMethod.updateGood(this.data.id,this.data.b_supplier_id,info.id, info.pr_num, this.data.tszhcontent,info.level_true_price,info.level_single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }
      }else if(this.data.price_type==1){ //客户历史价
        if(this.data.tan_is_auxiliary==1){ //是辅助单位
          if(this.data.aux_pf_list.length==0){   //当接口还未获取到辅助单位列表时return
            return;
          };
          var aux_item=this.data.aux_pf_list[this.data.aux_pf_index];
          var nor_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
          aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
          app.myMethod.updateGood(this.data.id,this.data.b_supplier_id,info.id,info.pr_num, this.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num,'',nor_price_obj.true_price);
        }else{  //非辅助单位
          app.myMethod.updateGood(this.data.id,this.data.b_supplier_id,info.id, info.pr_num, this.data.tszhcontent,0,0,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num,'',info.true_price);
        }
      }else if(this.data.price_type==4){  //客户固定价
        if(this.data.tan_is_auxiliary==1){  //是辅助单位
          if(this.data.aux_pf_list.length==0){   //当接口还未获取到辅助单位列表时return
            return;
          };
          var aux_item=this.data.aux_pf_list[this.data.aux_pf_index];
          var nor_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
          aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
          app.myMethod.updateGood(this.data.id,this.data.b_supplier_id,info.id,info.pr_num, this.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else{     //非辅助单位
          app.myMethod.updateGood(this.data.id,this.data.b_supplier_id,info.id, info.pr_num, this.data.tszhcontent,info.true_price,info.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        };
      }else{   //客户询价
        if(this.data.tan_is_auxiliary==1){  //是辅助单位
          if(this.data.aux_pf_list.length==0){   //当接口还未获取到辅助单位列表时return
            return;
          };
          var aux_item=this.data.aux_pf_list[this.data.aux_pf_index];
          var nor_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
          aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
          app.myMethod.updateGood(this.data.id,this.data.b_supplier_id,info.id,info.pr_num, this.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else{     //非辅助单位
          app.myMethod.updateGood(this.data.id,this.data.b_supplier_id,info.id, info.pr_num, this.data.tszhcontent,0,0,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        };
      }
    }else if(info.price_type==3){
      if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){ //模式5
        if(this.data.tan_shop_ku==1){   //库存商品
          if(this.data.is_ctrl_stock==1 && info.pr_num>0 && info.pr_num*1>this.data.tan_ku_num*1){
            wx.showLoading({
              title:'库存不足',
              duration:500
            });
            return;
          };
          var kucun_price_obj={'true_price':this.data.tan_ku_price,'single_price':0};
          if(this.data.tan_is_auxiliary==1){  //是辅助单位
            if(this.data.aux_kucun_list.length==0){   //当接口还未获取到库存辅助单位列表时return
              return;
            };
            var aux_item=this.data.aux_kucun_list[this.data.aux_kucun_index];
            aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
            if(this.data.shop_is_same==0){  //是否开启采销同价
              kucun_price_obj={'true_price':aux_item.sale_price,'single_price':aux_item.sale_price};
            }else if(this.data.shop_is_same==1){
              kucun_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
            };
          };
          app.myMethod.updateGood(this.data.id,this.data.group_id,info.id, info.pr_num, this.data.tszhcontent,kucun_price_obj.true_price,kucun_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else if(this.data.tan_shop_ku==0){   //非库存商品
          if(this.data.is_zi_cai==0 || this.data.assign_super_index>-1){  //非自采
            if(this.data.assign_superlist.length==0){   //当接口还未获取到供应商时return
              return;
            };
            var assign_item=this.data.assign_superlist[this.data.assign_super_index];
            var nor_price_obj={'true_price':info.true_price,'single_price':0};
            if(this.data.tan_is_auxiliary==1){  //是辅助单位
              aux_obj={'is_aux':1,'pr_unit':assign_item.sub_unit,'sub_unit_num':assign_item.sub_unit_num};
              nor_price_obj={'true_price':assign_item.sub_price,'single_price':assign_item.sub_price};
            };
            app.myMethod.updateGood(this.data.id,assign_item.supplier_id,info.id, info.pr_num, this.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num,assign_item.submit_price);
          }else if(this.data.is_zi_cai==1 && this.data.assign_super_index==-10010){  //自采
            app.myMethod.updateGood(-10010,-10010,info.id, info.pr_num, this.data.tszhcontent,info.true_price,0,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
          };
        };     
      }else if(this.data.good_dir_set==2 && this.data.purchase_type==2){  //模式6,7
        app.myMethod.updateGood(this.data.id,this.data.group_id,info.id, info.pr_num, this.data.tszhcontent,info.true_price,0,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
      }else{  //模式1,4及其他
        app.myMethod.updateGood(this.data.id,this.data.b_supplier_id,info.id, info.pr_num, this.data.tszhcontent,info.true_price,0,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
      };
    }else if(info.price_type==4){
      if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){  //模式5
        if(this.data.tan_shop_ku==1){
          if(this.data.is_ctrl_stock==1 && info.pr_num>0 && info.pr_num*1>this.data.tan_ku_num*1){
            wx.showLoading({
              title:'库存不足',
              duration:500
            });
            return;
          };
          var kucun_price_obj={'true_price':this.data.tan_ku_price,'single_price':this.data.tan_ku_price};
          if(this.data.tan_is_auxiliary==1){  //是辅助单位
            if(this.data.aux_kucun_list.length==0){   //当接口还未获取到库存辅助单位列表时return
              return;
            };
            var aux_item=this.data.aux_kucun_list[this.data.aux_kucun_index];
            aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
            if(this.data.shop_is_same==0){  //是否开启采销同价
              kucun_price_obj={'true_price':aux_item.sale_price,'single_price':aux_item.sale_price};
            }else if(this.data.shop_is_same==1){
              kucun_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
            };
          };
          app.myMethod.updateGood(this.data.id,this.data.group_id,info.id, info.pr_num, this.data.tszhcontent,kucun_price_obj.true_price,kucun_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else if(this.data.tan_shop_ku==0){
          if(this.data.is_zi_cai==0 || this.data.assign_super_index>-1){  //非自采
            if(this.data.assign_superlist.length==0){   //当接口还未获取到供应商时return
              return;
            };
            var assign_item=this.data.assign_superlist[this.data.assign_super_index];
            var nor_price_obj={'true_price':assign_item.unit_price,'single_price':assign_item.unit_price};
            if(this.data.tan_is_auxiliary==1){  //是辅助单位
              aux_obj={'is_aux':1,'pr_unit':assign_item.sub_unit,'sub_unit_num':assign_item.sub_unit_num};
              nor_price_obj={'true_price':assign_item.sub_price,'single_price':assign_item.sub_price};
            };
            app.myMethod.updateGood(this.data.id,assign_item.supplier_id,info.id, info.pr_num, this.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num,assign_item.submit_price);
          }else if(this.data.is_zi_cai==1 && this.data.assign_super_index==-10010){   //自采
            app.myMethod.updateGood(-10010,-10010,info.id, info.pr_num, this.data.tszhcontent,info.true_price,info.true_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
          };
        };  
      }else if(this.data.good_dir_set==2 && this.data.purchase_type==2){  //模式6,7
        app.myMethod.updateGood(this.data.id,this.data.group_id,info.id, info.pr_num, this.data.tszhcontent,info.true_price,info.true_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
      }else{  //模式1,4及其他
        app.myMethod.updateGood(this.data.id,this.data.b_supplier_id,info.id, info.pr_num, this.data.tszhcontent,info.true_price,info.true_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
      };
    }else if(info.price_type==5){
      if(this.data.good_dir_set==2 && this.data.client_is_store==0 && this.data.purchase_type==1){  //模式5
        if(this.data.tan_shop_ku==1){   //库存商品
          if(this.data.is_ctrl_stock==1 && info.pr_num>0 && info.pr_num*1>this.data.tan_ku_num*1){
            wx.showLoading({
              title:'库存不足',
              duration:500
            });
            return;
          };
          var kucun_price_obj={'true_price':this.data.tan_ku_price,'single_price':this.data.tan_ku_price};
          if(this.data.tan_is_auxiliary==1){  //是辅助单位
            console.log(999)
            if(this.data.aux_kucun_list.length==0){   //当接口还未获取到库存辅助单位列表时return
              console.log(789)
              return;
            };
            var aux_item=this.data.aux_kucun_list[this.data.aux_kucun_index];
            aux_obj={'is_aux':1,'pr_unit':aux_item.sub_unit,'sub_unit_num':aux_item.sub_unit_num};
            if(this.data.shop_is_same==0){  //是否开启采销同价
              kucun_price_obj={'true_price':aux_item.sale_price,'single_price':aux_item.sale_price};
            }else if(this.data.shop_is_same==1){
              kucun_price_obj={'true_price':aux_item.sub_price,'single_price':aux_item.sub_price};
            };
          };
          app.myMethod.updateGood(this.data.id,this.data.group_id,info.id, info.pr_num, this.data.tszhcontent,kucun_price_obj.true_price,kucun_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
        }else if(this.data.tan_shop_ku==0){   //非库存商品
          if(this.data.is_zi_cai==0 || this.data.assign_super_index>-1){  //非自采
            if(this.data.assign_superlist.length==0){   //当接口还未获取到供应商时return
              return;
            };
            var assign_item=this.data.assign_superlist[this.data.assign_super_index];
            var nor_price_obj={'true_price':assign_item.unit_price,'single_price':assign_item.unit_price};
            if(this.data.tan_is_auxiliary==1){  //是辅助单位
              aux_obj={'is_aux':1,'pr_unit':assign_item.sub_unit,'sub_unit_num':assign_item.sub_unit_num};
              nor_price_obj={'true_price':assign_item.sub_price,'single_price':assign_item.sub_price};
            };
            app.myMethod.updateGood(this.data.id,assign_item.supplier_id,info.id, info.pr_num, this.data.tszhcontent,nor_price_obj.true_price,nor_price_obj.single_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num,assign_item.submit_price);
          }else if(this.data.is_zi_cai==1 && this.data.assign_super_index==-10010){  //自采
            app.myMethod.updateGood(-10010,-10010,info.id, info.pr_num,this.data.tszhcontent,info.sale_price,info.sale_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
          };
        };  
      }else if(this.data.good_dir_set==2 && this.data.purchase_type==2){   //模式6,7
        app.myMethod.updateGood(this.data.id,this.data.group_id,info.id, info.pr_num, this.data.tszhcontent,info.sale_price,info.sale_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
      }else{    //模式1,4及其他
        app.myMethod.updateGood(this.data.id,this.data.b_supplier_id,info.id, info.pr_num, this.data.tszhcontent,info.sale_price,info.sale_price,1,aux_obj.is_aux,aux_obj.pr_unit,aux_obj.sub_unit_num);
      };
    };
    util.hideBuyModal(this,"isInput");
    if (info.pr_num > 0) {
      util.touchOnGoods(this,event.touches["0"],this.data.id,'nopand',1);
    }else{
      util.car_total(this,this.data.id,1);
    }
    this.setData({
      shangpin:'',
      isaufocus:true,
      ["rightDatas[" + this.data.inputIndex + "]"]: info,
      inputNum: "",
      content: "",
      tszhcontent: '',
      inputIndex: -1
    });  
  },
  // 关闭商品数量弹窗
  cancel: function () {
    util.hideBuyModal(this,"isInput");
    this.setData({
      inputIndex: -1,
      inputNum: "",
      tannum:'',
      shopnum:'',
      shoppr_num:'',
      tszhcontent: '',
      tangui: "",
      content: ""
    });
  },
  // 键盘按键
  keyTap(e) {
    util.keyfunction(e,this,3);
    if(this.data.isfeibiao==true){
      this.fbsetValue();
    }else if(this.data.isinput_col==true){
      this.col_setValue();
    }else{
      this.setValue();
    };
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.setNavigationBarTitle({
      title: options.supername + " | " + "搜索"
    });
    that.setData({
      is_zi_cai:app.globalData.loginInfo.is_zi_cai,  //是否自采
      good_dir_set:app.globalData.loginInfo.good_dir_set,    //目录类型
      client_is_store:app.globalData.loginInfo.client_is_store,  //<0未加入集团，==0加入集团无库 ,==1加入集团有库
      purchase_type:app.globalData.loginInfo.purchase_type,  //1门店采购，2总部采购
      is_ctrl_stock:app.globalData.loginInfo.is_ctrl_stock,  //库存控制开启（1开，0关），1库存不足则不可下单
      group_id:app.globalData.loginInfo.group_id,
      group_name:app.globalData.loginInfo.group_name,  //集团名称
      show_price_type:options.show_price_type,
      supername: options.supername,
      id: options.id,
      b_supplier_id:0,   //b_supplier_id传值
      price_type:options.price_type,   //客户定价模式
      type_level:app.globalData.type_level,
      unit_height:0.64* wx.getSystemInfoSync().windowHeight,
      two_specs_h:0.6* wx.getSystemInfoSync().windowHeight,
      raplace_h:0.75*wx.getSystemInfoSync().windowHeight
    });
    util.car_total(this,this.data.id,1);
    if(app.globalData.loginInfo.good_dir_set>1 || app.globalData.loginInfo.good_dir_set<1 && app.globalData.type_level==1){  //获取一级分类(client)
      app.AppHttp('api/Order/getClientOneClass', {
        client_id:app.globalData.loginInfo.id
      }, function (res) {
        console.log(JSON.stringify(res.data));
        that.setData({
          types:res.data,
          is_open_standard:1,
          is_non_standard:1
        })
      });
    }else if(app.globalData.loginInfo.good_dir_set==1 || app.globalData.loginInfo.good_dir_set<1 && app.globalData.type_level==0){   //获取一级分类(super)
      app.AppHttp('api/Client/supperDetail', {  
        openid: app.globalData.openid,
        id: options.id
      }, function (res) {
        that.setData({
          is_non_standard: res.data.data.is_non_standard
        });
      });
      if(app.globalData.loginInfo.good_dir_set==1){
        app.AppHttp('api/Goods/getIsOpenStandard', {
          client_id:app.globalData.loginInfo.id,
          supplier_id: options.id,
          group_id:app.globalData.loginInfo.group_id
        }, function (res) {
          console.log(JSON.stringify(res.data));
          that.setData({
            is_open_standard:res.data.data.is_open_standard
          });
        });
      }else{
        that.setData({
          is_open_standard:1
        });
      };
      app.AppHttp('api/Orders/getOneClass', {
        openid: app.globalData.openid,
        supplier_id: options.id
      }, function (res) {
        console.log(JSON.stringify(res.data));
        that.setData({
          types:res.data
        })
      });
    }
  },
  noneEnoughPeople:function(){
    return;
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (app.globalData.changyong_show == 1) {
      wx.pageScrollTo({
        scrollTop: 0,
        duration: 0
      });
      this.setData({
        page: 1,
        load: "搜索中..."
      });
      this.viewck();
      util.car_total(this,this.data.id,1);
    }
    this.busPos = {};
    this.busPos['x'] = app.globalData.ww * 0.1;
    this.busPos['y'] = app.globalData.hh * 0.94;
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      page: 1,
      load: "搜索中..."
    });
    this.viewck();
    util.car_total(this,this.data.id,1);
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (that.data.page < that.data.allpage) {
      that.setData({
        page: that.data.page + 1,
        isChooseAll: false,
        load: '加载更多',
        loading:1
      });
      that.upshoplist();
    } else {
      wx.showToast({
        title: '没有了'
      });
      this.setData({
        loading:0
      });
    }
  }
})